<?php
/**
 * Here we go!
 */

define('MP_PATH', str_replace('\\', '/', dirname(__FILE__)));

/**
 * Autoloader for classes
 *
 * Thanks to Habari for inspiration
 */
function __autoload($class_name) {
	static $files = null;
	$exclude = array('idna_convert.php' => true);

	$success = false;
	$class_file = strtolower($class_name) . '.php';

	if( empty($files) ) {
		$files = array();
		$dirs= array( MP_PATH . '/mp-includes' );

		// For each directory, save the available files in the $files array.
		foreach ($dirs as $dir) {
			$glob = glob( $dir . '/classes/*.php' );
			if ( empty( $glob ) )
				continue;
			$fnames = array_map(create_function('$a', 'return strtolower(basename($a));'), $glob);
			$files = array_merge($files, array_combine($fnames, $glob));
		}
	}

	// Search in the available files for the undefined class file.
	if(isset($files[$class_file])) {
		require_once $files[$class_file];
		// If the class has a static method named __static(), execute it now, on initial load.
		if(class_exists($class_name, false) && method_exists($class_name, '__static') ) {
			call_user_func(array($class_name, '__static'));
		}
		$success = true;
	}

	if(isset($exclude[$class_file]))
		return;

	if ( !$success ) {
		die( 'Could not include class file ' . $class_file );
	}
}

function __($text) {
	return $text;
}
function _e($text) {
	echo $text;
}

//Load libraries...
require_once(MP_PATH . '/mp-includes/simplepie.inc');

/** Get list of siblings */
Config::setup();
$siblings = Config::instance()->get('siblings');

/** Start the synchronization */
new Synchronizer($siblings);

?>